package com.chub.study.modules.service.impl;

import com.alibaba.fastjson2.JSONObject;
import com.chub.study.modules.service.FileProcessorService;

import java.util.ServiceLoader;

/**
 * @author : chub
 * @version : V1.0.0
 * @fileName : SPIDemo.java
 * @description : TODO
 * @createTime : 2024-08-01 15:07
 */
public class SPIDemo {
    public static void main(String[] agrs) {

        //使用jdk提供的类ServiceLoader来加载IMyService的子类
        ServiceLoader<FileProcessorService> loaders = ServiceLoader.load(FileProcessorService.class);

        JSONObject reqJson = new JSONObject();
        reqJson.put("type", "1");
        reqJson.put("fileId", "123456");
        reqJson.put("filePath", "D:\\test.txt");
        reqJson.put("fileSize", 1024);
        reqJson.put("fileType", "txt");
        reqJson.put("fileExt", "txt");
        reqJson.put("fileMd5", "123456");
        //遍历并调用子类方法
        for (FileProcessorService service : loaders) {
            if (service.matchFileType(reqJson.get("fileType").toString())) {


            }

            service.processor(reqJson);
        }
    }

}
